package t914

import "fmt"

func hasGroupsSizeX(deck []int) bool {

	cnt := len(deck)

	if cnt < 2 {
		return false
	}

	//得到牌数的因数
	factors := getFactor(cnt)

	//计数
	m := make(map[int]int)
	for _, i := range deck {
		m[i]++
	}

	res := false

	for _, factor := range factors {
		for _, i := range m {
			if i%factor == 0 {
				res = true
			} else {
				res = false
				break
			}
		}
		if res {
			break
		}
	}

	return res
}

// 获取因数
func getFactor(n int) []int {
	var factor []int
	for i := 2; i <= n; i++ {
		if n%i == 0 {
			factor = append(factor, i)
		}
	}
	return factor
}

func getGcd(a, b int) int {

	max := a
	if a < b {
		max = b
	}

	c := 20

	for i := 2; i <= max/2; i++ {
		if a%i == 0 && b%i == 0 && c%i == 0 {
			a, b = a/i, b/i
			c = c / i
			fmt.Println(i, a, b, c)
		}
	}

	fmt.Println(getFactor(a))
	fmt.Println(getFactor(b))

	return 0
}

// 2 | 30 40
// 5 | 15 20
//   |  3  4
